var Registros = {
    settings : {},
    
    init: function(options){
            
        var settings = $.extend({
            btnReloadList: null,
            listRegistros: null,
            
            formRegister: null,
            msgFormRegister: null,
            btnOpenRegister: null,
            divFormRegister:null, // Automatico
            divMsgFormRegister: null, // Automatico
            
            formEdit: null, 
            msgFormEdit: null,
            divFormEdit: null, // Automatico
            divMsgFormEdit: null // Automatico
            
        }, options);
        $.extend(this, Registros);
    
        if(settings.btnReloadList != null){
            var bReloadL = twoDotPrepare(settings.btnReloadList);
        
            settings['btnReloadList'] = $(bReloadL);
            settings.btnReloadList.button({
                text: false, 
                icons:{
                    primary: 'ui-icon-arrowrefresh-1-s'
                }
            });
        } // Boton actualizar lista
    
        if(settings.formRegister != null){
            var fRegister = twoDotPrepare(settings.formRegister);
        
            settings["divFormRegister"] = $("#div-"+fRegister);
            settings['divMsgFormRegister'] = $("#msg-"+fRegister);
            
            settings.divFormRegister.dialog({
                autoOpen: false, 
                modal:true, 
                show: 'bind', 
                hide: 'clip'
            });
        } // Ventana de Registro
    
        if(settings.btnOpenRegister != null){
            var bOpenReg = twoDotPrepare(settings.btnOpenRegister);
        
            settings['btnOpenRegister'] = $(bOpenReg);
            settings.btnOpenRegister.button({
                icons: {
                    primary:'ui-icon-plus'
                }
            }).click(function(evnt){
                this.divFormRegister.dialog("open");
            });
        } // Boton de registro
    
    
        if(settings.formEdit != null){
            var fEdit = twoDotPrepare(settings.formEdit);
        
            settings['divFormEdit'] = $("#div-"+fEdit);
            settings['divMsgFormEdit'] = $("#msgs-"+fEdit);
            settings.divFormEdit.dialog({
                autoOpen: false, 
                modal:true, 
                show: 'bind', 
                hide: 'clip',
                open: function(evnt, ui){
                    this.recargaFormEdit(ui, evnt);
                }
            });
        } // Ventana de edición

        this.settings = settings;
        return this;
    },
    
    recargaFormEdit: function(elm, evnt){
        mojarra.ab(elm, evnt, 'click', 0, this.settings.formEdit);
        return false;
    },


    recargaLista: function(elm, evnt){
        mojarra.ab(elm, evnt, 'click', 0, this.settings.listRegistros);
        return false;
    },

    // Eventos para la edicion de institucion
    openEdit: function(evnt){
        this.settings.divFormEdit.dialog("open");
        return false;
    },

    eventoEdicion: function(elm, evnt){
        var divMsgEdit = $("#msgs-"+twoDotPrepare(this.settings.formEdit));
        var baseEdita = new SATK.Forms.Msg(divMsgEdit, this.settings.msgFormEdit);
        var resp = SATK.Forms.ajaxResponce(evnt, baseEdita);    
        if(resp == 'true'){
            this.recargaLista(elm, evnt);
            setTimeout(function(obj){
                this.settings.divFormEdit.dialog("close");
                $(divMsgEdit).html("");
            }, 3000);
        }
    },

    eventCancelEdit: function(){
        var fEdit = twoDotPrepare(this.Bases.formEdit);
        $(Registros.Msg.msgFormEdit.elmBox).html("");
        $("#div-"+fEdit).dialog("close");
    },

    // Eventos para el registro de una institución
    eventRegistro: function(elm, evnt){
        var fRegister = twoDotPrepare(this.Bases.formRegister);
        var baseRegistro = new SATK.Forms.Msg("#msgs-"+fRegister , this.Msg.msgFormRegister);
        var resp = SATK.Forms.ajaxResponce(evnt, baseRegistro);
        if(resp == 'true'){
            this.recargaLista(elm, evnt);
        }
    }
};